package 力扣;

import Stack.Stack;

/**
 * @author yyq
 * @create 2022-04-18 10:38
 */
public class leetcode530 {
    public int getMinimumDifference(TreeNode root) {
        int[] mini= new int[1];
        mini[0]=root.val - root.left.val;
        int[] upVal=new int[1];
        int[] start=new int[1];
        start[0] = -1;
        inOrder(root,mini,upVal,start);
        return mini[0];
    }
    private void inOrder(TreeNode root, int[] mini, int[] upVal, int[] start) {
        boolean flag = true;
        if(root.left!=null){
            inOrder(root.left,mini,upVal,start);
        }

        if(start[0]==-1) {
            upVal[0] =root.val;
            start[0] = 1;
        }
        else {
            int temp = root.val-upVal[0];
            if(mini[0]>temp){
                mini[0] = temp;
            }
        }

        if(root.right!=null){
            inOrder(root.right,mini,upVal,start);
        }


    }
}
